package rollercoaster.commons;

import java.io.File;
import java.io.IOException;

import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLException;

import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;

public class Material {

	private Texture tex;
	private String texturepath;
	private int texture;
	private float[] transformMatrix;
	
	
	public Material(String texturepath) {
		super();
		this.texturepath=texturepath;
		
	}

	

	public void setTransformMatrix(float[] transformMatrix) {
		this.transformMatrix = transformMatrix;
	}



	public int getTexture() {
		return texture;
	}

	public void init(GL2ES2 gl){
		try {
			this.tex = TextureIO.newTexture(new File(texturepath), true);
			texture=tex.getTextureObject(gl);
		} catch (GLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void apply(GL2ES2 gl, int textureTransform){
		
		gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
	    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
	    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
	    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
	    gl.glUniformMatrix2fv(textureTransform, 1, false, transformMatrix,0);
	}
	
	
	
}
